//
//  ViewController.swift
//  CosClub
//
//  Created by iOS on 2020/3/9.
//  Copyright © 2020 ios. All rights reserved.
//

import UIKit

open class BaseViewController: UIViewController {
    
    public typealias NavViewType = NavView.BackType
    
    public var navigationBarView: NavView?
    
    public var navigationVC :NavigationViewController? {
        self.navigationController as? NavigationViewController
    }
    
    public var tabBarVC :BaseTabBarViewController? {
        self.tabBarController as? BaseTabBarViewController
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.navigationController?.navigationBar.isHidden = true
        // Do any additional setup after loading the view.
        
        if #available(iOS 11.0, *) {
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
    }
    
    public func addNavBar (_ title: String? = "" ,type: NavViewType = .white){
        let nav = NavView(type: type) { [weak self] in
            self?.navigationController?.popViewController(animated: true)
        }
        self.navigationBarView = nav
        view.addSubview(nav)
        nav.makeLayout(NavBarLayout(height: navStatusHeight, superView: view))
        nav.title = title
    }
   
    deinit {
        print("\(NSStringFromClass(self.classForCoder))释放")
    }
    
    open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
    }
}

extension BaseViewController {
    public var navStatusHeight :CGFloat {
        guard let nav = self.navigationController else {
            return 0
        }
        return nav.height + statusBarHeight
    }
}
